package br.odb.bzk3.android;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import br.odb.bzk3.android.storytelling.StoryTellingActivity;
import br.odb.utils.Utils;
/**
 * 
 * @author monty
 *
 */
public class AppStart extends Activity implements OnClickListener {
	/**
	 * 
	 */
	private Button btn;
	/**
	 * 
	 */
	private Spinner cbo;
	/**
	 * 
	 */
	private MediaPlayer mp;
	// ------------------------------------------------------------------------------------------------------------
	/**
	 * 
	 */
	@Override
	public void finish() {

		onLostFocus();
		super.finish();
	}

	// ------------------------------------------------------------------------------------------------------------
	/**
	 * 
	 */
	@Override
	public void onClick(View view) {
		onLostFocus();
		EngineActivity.selected = cbo.getSelectedItemPosition();

		switch (view.getId()) {
		case R.id.btPlay:
			startActivity(new Intent(this, EngineActivity.class));
			break;
		case R.id.btStory:
			startActivity(new Intent(this, StoryTellingActivity.class));
			break;
		}
	}

	// ------------------------------------------------------------------------------------------------------------
	/** 
	 * Called when the activity is first created. 
	 * */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mp = MediaPlayer.create(this, R.raw.angstron2theme);
		// mp.start();
		Utils.eqFloat(1.0f, 1.5f);
		setContentView(R.layout.main);

		cbo = (Spinner) findViewById(R.id.spnLevels);

		ArrayAdapter<Object> spinnerArrayAdapter = new ArrayAdapter<Object>(
				this, android.R.layout.simple_spinner_dropdown_item,
				new String[] { "teste1", "teste2", "teste3" });
		cbo.setAdapter(spinnerArrayAdapter);

		btn = (Button) findViewById(R.id.btPlay);
		btn.setOnClickListener(this);

		btn = (Button) findViewById(R.id.btStory);
		btn.setOnClickListener(this);
	}
	// ------------------------------------------------------------------------------------------------------------
	/**
	 * 
	 */
	private void onLostFocus() {

		if (mp != null)
			mp.stop();
	}
}
